#include <buola/scene/cbonetransform.h>
#include <buola/scene/cbone.h>

namespace buola { namespace scene {

CBoneTransform::CBoneTransform(CBone *pBone)
    :   mBone(pBone)
{
}

void CBoneTransform::InvalidateTransform()
{
    mLocalTransformValid=false;
}

void CBoneTransform::CalcLocalTransform()
{
    mat::CQuat_d lTransform;

    for(int i=0;i<mBone->mJoints.size();i++)
        lTransform=lTransform*mat::CQuat_d(mBone->mJoints[i]->mValue,mBone->mJoints[i]->mAxis);

    mLocalTransform=mat::translation_3d(mBone->mOrigin)*
                    mat::rotation_3d(mBone->mOrientation*lTransform*conj(mBone->mOrientation))*
                    mat::translation_3d(-mBone->mOrigin);

    mLocalTransformValid=true;
}

/*namespace scene*/ } /*namespace buola*/ }
